﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NHibernate;
using My.Data.Factories;
using My.Data.BusinessObject;

namespace Gui
{
    public partial class MainFormTeacher : Form
    {
        private static MainFormTeacher instance_ = null;

        public MainFormTeacher()
        {
            InitializeComponent();
        }

        public static MainFormTeacher getInstance()
        {
            if (null == instance_)
            {
                instance_ = new MainFormTeacher();
            }
            return instance_;
        }

        private void MainFormTeacher_Load(object sender, EventArgs e)
        {
            IBridge bridge = new AdminTeacherBridge();
            AbstractBridge abBridge = new AbstractBridge(bridge);
            abBridge.CallFillTable(mainTable);
        }

        private void DeleteBtn_Click(object sender, EventArgs e)
        {
            IBridge bridge = new AdminTeacherBridge();
            AbstractBridge abBridge = new AbstractBridge(bridge);
            abBridge.CallDeleteUser(mainTable);
            abBridge.CallClearTable(mainTable);
            abBridge.CallFillTable(mainTable);
        }

        int close = 0;
        private void MainFormTeacher_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (close == 0)
            {
                if (MessageBox.Show("close the program?", "Continue?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    close = 1;
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
    }
}